<template>
    <div class="box">
        <h3>点击了{{$store.state.time}} 次,当前次数为{{sum}}</h3>
        <button @click="addition">+</button>
        <button @click="subtraction">-</button>
        <button @click="evenAdd">偶数加法</button>
        <button @click="asyncAdd">异步加法</button>
    </div>
</template>

<script>
    export default {
        name: "App",
        computed:{
            sum(){
                return this.$store.getters.sum;
            }
        },
        methods:{
            addition(){
                //通知vuex去增加
                this.$store.dispatch('addition');
            },
            subtraction(){
                this.$store.dispatch('subtraction');
            },
            evenAdd(){
                this.$store.dispatch('evenAdd');
            },
            asyncAdd(){
                this.$store.dispatch('asyncAdd');
            }
        }
    }
</script>

<style scoped>
    .box{
        margin-left: 30px;
    }
</style>